restful-api.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 8
Bugs 0 Features 0
Metric Value
cc 1
c 8
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
1
import axios from 'axios';
2
3
4
5
export default class CommentsApi {
6
7
	constructor(baseUrl = '/comments/') {
8 2
		this.axios = axios.create({
9
			baseURL: baseUrl
10
		});
11
12 2
		this.axios.defaults.headers.common['Accept'] = 'application/json';
13
	}
14
15
	getComments(model, id, parentId = null, params = {}) {
16
		let url = model + '/' + id;
17
18 4
		if (parentId !== null) {
19
			url = url + '/' + parentId
20
		}
21
22
		return this.axios.get(url, {
23
			params: params
24
		});
25
	}
26
27
	getCommentsBefore(model, id, parentId = null, time, params = {}) {
28
		params.before = time;
29
		return this.getComments(model, id, parentId, params);
30
	}
31
32
	getCommentsAfter(model, id, parentId = null, time, params = {}) {
33
		params.after = time;
34
		return this.getComments(model, id, parentId, params);
35
	}
36
37
	add(model, id, data) {
38
		return this.axios.post(model + '/' + id, data);
39
	}
40
41
	remove(model, id, commentId) {
42
		return this.axios.delete(model + '/' + id + '/' + commentId);
43
	}
44
45
	update(model, id, commentId, data) {
46
		this.axios.patch(model + '/' + id + '/' + commentId, data)
47
	}
48
}
49